package com.jia.leetCode;

/**
 * 925.长按键入
 *
 */
public class Pro0925 {
    public boolean isLongPressedName(String name, String typed) {
        int nLen = name.length(), tLen = typed.length();
        int j = 0;
        for(int i = 0; i < tLen; i++) {
            if(j < nLen && name.charAt(j) == typed.charAt(i)) {
                ++j;
            }else if(j < nLen && name.charAt(j) != typed.charAt(i)) {
                if(i == 0 || typed.charAt(i) != typed.charAt(i - 1)) {
                    return false;
                }
            }else if(j == nLen && typed.charAt(i) != typed.charAt(i - 1)) {
                return false;
            }
        }
        return j == nLen;
    }

    public static void main(String[] args) {
        Pro0925 pro0925 = new Pro0925();
        String name = "alex";
        String typed = "alexxr";
        System.out.println(pro0925.isLongPressedName(name, typed));;
    }
}
